import React, {Component} from 'react';
import {Button, Progress} from 'antd';
import DialogLoading from '../../components/DialogLoading/DialogLoading';
import {cutHandle, testArray, requestStep} from './baipei';

class App extends Component {
    constructor(props) {
        console.log('my')
        super(props);
        this.state = {
            showLoading: false,
            loadingProgress: 0,
        }
    }
    startTask() {
        this.setState({
            showLoading: true,
        })
        cutHandle(testArray, 10, this.requestStep.bind(this), this.resultRequest.bind(this));
    }
    requestStep (data, {progress}) {
        console.log(data)
        console.log(progress)
        console.log(this)
        this.setState({
            loadingProgress: +progress * 100,
        })
        return new Promise((resolve) => {
            setTimeout(() => {
                resolve({
                    errList: [data[3], data[5]]
                })
            }, 1000)
        });
    };
    resultRequest(res) {
        console.log(res)
        this.setState({
            showLoading: false,
        })
    }
    render() {
        return (
            <div>
                <Button onClick={this.startTask.bind(this)}>开始</Button>
                {
                    this.state.showLoading ? 
                    <DialogLoading num={this.state.loadingProgress}>
                        <div>正在上传中，请稍等</div>
                    </DialogLoading>
                    : ''
                }
            </div>

        );
    }
}
export default App;
